<?php
/**
 * oppo产品模型
 *
 * @author qianyunlai.com
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class table_oppo_permission extends discuz_table {

	public function __construct() {

		$this->_table = 'oppo_permission';
		$this->_pk = 'permission_id';

		parent::__construct();
	}

	/**
	 * 根据用户ID获取信息
	 *
	 * @param string $uid
	 */
	public function fetch_by_uid($uid) {
		if (!$uid) {
			return false;
		}
		$permissionInfo = array();
		$permissionInfo = DB::fetch_first('SELECT * FROM %t WHERE uid=%d', array($this->_table, $uid));

		return $permissionInfo;
	}

	/**
	 * 根据用户ID更新数据
	 *
	 * @param int $uid 用户ID
	 * @param array $data 新数据
	 * @return boolean
	 */
	public function update_by_uid($uid, $data) {
		if (($uid = intval($uid)) && !empty($data) && is_array($data)) {
			return DB::update($this->_table, $data, array('uid' => $uid));
		}
		return 0;
	}

	/**
	 * 查询所有的用户
	 */
	public function fetch_all() {
		return DB::fetch_all('SELECT * FROM %t ORDER BY update_time desc', array($this->_table));
	}

	/**
	 * 删除用户
	 *
	 * @param int $uid 用户ID
	 */
	public function del_by_uid($uid) {
		if (!$uid) {
			return false;
		}
		$where = 'uid=' . intval($uid);

		return DB::delete($this->_table, $where);
	}
}

?>